package org.example.library.util;

import java.sql.*;

public class JDBCutils {
    private static String USER = "root";
    private static String PASSWORD = "123456";
    private static String URL = "jdbc:mysql://localhost:3306/library";
    private static String DRIVER = "com.mysql.cj.jdbc.Driver";

    public static Connection getconnection() throws SQLException, ClassNotFoundException {
        Class.forName(DRIVER);
        return DriverManager.getConnection(URL,USER,PASSWORD);
    }

    public static void release(ResultSet rs,PreparedStatement ps,Connection connection){
        try{
            if(rs!=null){
                rs.close();
            }
            if(ps!=null){
                ps.close();
            }
            if(connection!=null){
                connection.close();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }

    }
}
